<? 

	include "jumaro-main.inc.php";
	
	include "jumaro-dal.php";
	
	include "clases/_message.class.php";
	
	include "clases/_table.class.php";
	
	include "clases/_buttons.class.php";
	
	include "_resources/_resourcesNegocios.php";
	include "_resources/_resourcesCategorias.php";
	
	_checkSESSION();
	
	$message_text = "";
	
	if($_POST['cmd_object']){
		
		$message = new _message();
		
		$message->set_width('600px');
		
		switch ($_POST['_op']){
			case "DLT":
					$datos = $_POST['chk'];
					
					foreach ($datos as $index) {
						elimimarPublicaciones($index);
					}
					
					$message->set_message('se ejecuto su operacion.-','exitos');
					
				break;
			case "DLTU":
					
						elimimarPublicaciones($_POST['_i']);
						
						$message->set_message('se elimino la publicacion seleccionada.-','exitos');
					
				break;
		
			default:
				break;
		}

		$message_text = $message->get_message();

	}



#----------------------------------------------------------------------------------

		$id_user = $_SESSION['usr']['id'];
		

		if(!session_get_var('pagging_ad')){ session_add_var('pagging_ad',0); }	
		
		$pagging = (isset($_GET['p'])) ? $_GET['p'] : session_get_var('pagging_ad') ;
		
		session_add_var('pagging_ad',$pagging);

		$conditions[] = "publicacion.id_usuario = $id_user";
		
		$datos = $_POST;
		//var_export($datos);die();
		if($datos['cmd_search']){

			$conditions[] = "publicacion.nombre LIKE '%{$datos['sNombre']}'";
			
			/*if($datos['idNegocio'] != 0 && $datos['idNegocio'] != ""){
				$conditions[] = "negocio.id = '{$datos['idNegocio']}'";
			}*/

			session_add_var('ad_sNombre',$datos['sNombre']);			
			session_add_var('pagging_ad',0);//reset to pagging
			
		}else{

			$sNombre 		= session_get_var('ad_sNombre');			
			
			
			$conditions[] = "publicacion.nombre LIKE '%{$sNombre}'";			

			/*if($idNegocio != 0 && $idNegocio != ""){
				$conditions[] = "negocio.id = '{$idNegocio}'";
			}*/
		}
		
		$table = new _table_('anuncios');
		
		if($_GET['field_order']){
			$table->set_table_num_field_order($_GET['field_order']);
			//session_add_var('pagging_users',0);//reset to pagging
		}
		
		if($_GET['type_order']){
			$table->set_table_type_order($_GET['type_order']);
			//session_add_var('pagging_users',0);//reset to pagging
		}
		
		$table->set_table_SQL(getSQLPublicaciones());	
		
		$table->set_object_to_count(getSQLPublicaciones(false));
		
		$table->set_table_enable_checkbox(true);

		$table->set_table_headers('Fecha,Publicacion,Usuario,Activo');
		
		$table->set_table_fields_orders("publicacion.fecha,publicacion.nombre,usuario.apellido");

		$table->set_table_number_operations(2);
		
		$table->set_table_width(900);

		$table->set_table_enable_pagging(true);
		
		$table->set_table_name_pagging('pagging_ad');
		
		$table->set_table_template_rows('anuncios');
		
		

		if(sizeof($conditions) > 0) $table->set_table_sconditions(implode(" AND ",$conditions));

		else $table->set_table_sconditions( '1' );

		//$table->set_table_url_form( '' );

		//$table->set_table_comment( $table_comment );	

		$table->set_table_orders( 'publicacion.fecha' );

		//$table->set_table_label("");

		//$table->set_table_view_record_found(true);
		
		//var_export($table->print_table());die();
		
		$table_users = $table->print_table();
		
		$buttons = new _buttons_('R');	
		
		$buttons->add_button('href',"alta-anuncio.php",'agregar','new');
		
		$buttons->add_button('href',"javascript:_alertDLT();",'Eliminar Seleccionados','delete');
	
		$buttons->set_width('900px;');
		
		$botonera = $buttons->get_buttons();
						
#----------------------------------------------------------------------------------


//cabeceraHtml_beta("JUMARO Menu administracion", "salta,precio,descuentos", "", "");

htmlHEADER("JUMARO Menu administracion", "salta,precio,descuentos", "");
?>


<div class="bg_body">
<div class="bg2_body">
<div class="wrapper-padd">
<div id="bodyWrapper" class="container_16 ofh">

<?
inicioEncabezado();
		mostrarLogo();		
		menuSuperior(3);
finEncebezado();

//A partir de aqui muestro el contenido de la pagina
inicioContenidoNoMenuLateral();
	tituloContenido('Administracion de Anuncios');
?>



	<div class="contentContainer log">
	  <div class="contentPadd loginPage" style="width:900px;">

			<div style="border-left: 0px solid #e5e5e5;">
				
				<div style="border: 0px solid #e5e5e5;" class="contentInfoText marg-top">
				
					<form action="" method="POST" name="form_search" id="form_search"><center>
						<div style="width:900px;">
							<fieldset style="border-top:2px solid #000;border-right:0px solid #CCC;border-bottom:2px solid #000;border-left:0px solid #CCC;">
							<legend style="text-align:left;border:0px solid #FFF;">
								<img src='images/search32.png' title='buscar' alt='buscar' hspace='4' align='absmiddle' />
								FILTRO PUBLICACIONES
							</legend>	
							
							<table style="width:600px !important;font-size:11px;" cellspacing="3" cellpadding="3" border="0">
							 <tr>
							  	<td align="right" width="140">Publicacion:</td>
							  	<td width=""><input type="text" name="sNombre" id="sNombre" value='<?=$_POST['sNombre']?>' style='width:150px;'></td>
							 </tr>
							 <tr>
								<td align="center" colspan="2">
									&nbsp;
								</td>
							 </tr>		 
							 <tr>
								<td align="center" colspan="2">
									<input type='submit' name='buscar' style="width:120px;padding:5px;" value="Buscar">
									<input type="hidden" name="cmd_search" id="cmd_search" value="1" />
								</td>
							 </tr>
							 </table>		
							</fieldset>
						</div>
						</center>
						
					</form>
					
					<br />
					

					<?
					
						echo $message_text;
					
						echo $botonera;
					
						echo $table_users;
						

					?>


	
			</div>
				<div>
				    <span class="inputRequirement"></span>
				</div>			
		</div>
	</div>
	
</div>


<?php 
finContenido();
//menuIzquierdo();
?>

</div>
</div>
</div>
</div>
<?php 
pie();
?>	
</body>
<!--[if IE]>
  <link href="css/ie_style.css" rel="stylesheet" type="text/css" />
<![endif]-->
</html>
<script type="text/javascript">


	function checkTodos(id,pID){
	
	   $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked')); 
	
	}
	
	function _alertDLT(){
		var ok = confirm('Es seguro de realizar esta operacion ?');
		
		if(ok){ send_form(0,'DLT'); }
		
	}
	
	function _alertDLTU(_i){
		var ok = confirm('Es seguro de Eliminar la publicacion ?');
		
		if(ok){ send_form(_i,'DLTU'); }
		
	}

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-7078796-2");
pageTracker._trackPageview();
} catch(err) {}</script>
	
	
	
	
